package cn.yikaojiuguo.student.ui.my;

import android.content.Context;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import cn.yikaojiuguo.student.R;
import cn.yikaojiuguo.student.adapter.DialogChooseAdapter;
import cn.yikaojiuguo.student.bean.Category;
import cn.yikaojiuguo.student.support.database.MyDBManager;
import cn.yikaojiuguo.student.support.simple.ArgsConstants;
import cn.yikaojiuguo.student.ui.base.BasePopupWindow;

/**
 * Created by cfan_yang on 2016/1/12.
 */
public class InfoChoosePopupWindow extends BasePopupWindow {

    public final static int CHOOSE_MAJOR = 1;
    public final static int CHOOSE_GRADE = 2;
    public final static int CHOOSE_PROVINCE = 3;

    /**
     * 初始化PopupWindow
     *
     * @param context
     * @param widthPercent  PopupWindow宽度占屏幕百分比
     * @param heightPercent PopupWindow高度占屏幕百分比
     */
    public InfoChoosePopupWindow(Context context, float widthPercent, float heightPercent,int type) {
        super(context, widthPercent, heightPercent,type);
    }

    @Override
    protected void initEvent() {

    }


    @Override
    protected void initView(Context context) {
        TextView tv_title = (TextView) mConvertView.findViewById(R.id.tv_title);
        ListView lv = (ListView) mConvertView.findViewById(R.id.lv);
        DialogChooseAdapter adapter = null;
        List<Category> list = null;
        if(mType == CHOOSE_MAJOR) {
            tv_title.setText("选择专业");
            list = MyDBManager.queryByEvalue(ArgsConstants.EVALUE_MAJOR);
        } else if(mType == CHOOSE_GRADE) {
            tv_title.setText("选择年级");
            String gradeNames[] = mContext.getResources().getStringArray(R.array.grade);
            list = new ArrayList<Category>();
            int evalue = 1;
            for(String name:gradeNames) {
                Category category = new Category();
                category.ename = name;
                category.evalue = evalue;
                list.add(category);
                evalue++;
            }
        } else if(mType == CHOOSE_PROVINCE) {
            tv_title.setText("选择生源地");
            list = MyDBManager.queryByEvalue(ArgsConstants.EVALUE_PROVINCE);
        }
        adapter = new DialogChooseAdapter(mContext,list,mType);
        lv.setAdapter(adapter);
    }

    @Override
    protected int getLayoutResourceId() {
        return R.layout.layout_dialog_change;
    }

}
